You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
59
vendor/oss-sdk/tests/OSS/Tests/AclResultTest.php
vendored
Executable file
59
vendor/oss-sdk/tests/OSS/Tests/AclResultTest.php
vendored
Executable file
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
26
vendor/oss-sdk/tests/OSS/Tests/BodyResultTest.php
vendored
Executable file
26
vendor/oss-sdk/tests/OSS/Tests/BodyResultTest.php
vendored
Executable file
@ -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(), "");
|
||||
}
|
||||
}
|
77
vendor/oss-sdk/tests/OSS/Tests/BucketCnameTest.php
vendored
Executable file
77
vendor/oss-sdk/tests/OSS/Tests/BucketCnameTest.php
vendored
Executable file
@ -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;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->client = Common::getOssClient();
|
||||
$this->bucketName = 'php-sdk-test-bucket-' . strval(rand(0, 10000));
|
||||
$this->client->createBucket($this->bucketName);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$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']);
|
||||
}
|
||||
}
|
21
vendor/oss-sdk/tests/OSS/Tests/BucketInfoTest.php
vendored
Executable file
21
vendor/oss-sdk/tests/OSS/Tests/BucketInfoTest.php
vendored
Executable file
@ -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());
|
||||
}
|
||||
}
|
283
vendor/oss-sdk/tests/OSS/Tests/BucketLiveChannelTest.php
vendored
Executable file
283
vendor/oss-sdk/tests/OSS/Tests/BucketLiveChannelTest.php
vendored
Executable file
@ -0,0 +1,283 @@
|
||||
<?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;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->client = Common::getOssClient();
|
||||
$this->bucketName = 'php-sdk-test-rtmp-bucket-name-' . strval(rand(0, 10000));
|
||||
$this->client->createBucket($this->bucketName);
|
||||
Common::waitMetaSync();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
////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 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()));
|
||||
}
|
||||
}
|
297
vendor/oss-sdk/tests/OSS/Tests/CallbackTest.php
vendored
Executable file
297
vendor/oss-sdk/tests/OSS/Tests/CallbackTest.php
vendored
Executable file
@ -0,0 +1,297 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class CallbackTest extends TestOssClientBase
|
||||
{
|
||||
public function testMultipartUploadCallbackNormal()
|
||||
{
|
||||
$object = "multipart-callback-test.txt";
|
||||
$copiedObject = "multipart-callback-test.txt.copied";
|
||||
$this->ossClient->putObject($this->bucket, $copiedObject, file_get_contents(__FILE__));
|
||||
|
||||
/**
|
||||
* step 1. Initialize a block upload event, which is initialized to upload Multipart, get the upload id
|
||||
*/
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
/*
|
||||
* step 2. uploadPartCopy
|
||||
*/
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* step 3.
|
||||
*/
|
||||
|
||||
$json =
|
||||
'{
|
||||
"callbackUrl":"oss-demo.aliyuncs.com:23450",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"{\"mimeType\":${mimeType},\"size\":${size},\"x:var1\":${x:var1},\"x:var2\":${x:var2}}",
|
||||
"callbackBodyType":"application/json"
|
||||
}';
|
||||
|
||||
$var =
|
||||
'{
|
||||
"x:var1":"value1",
|
||||
"x:var2":"值2"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $json,
|
||||
OssClient::OSS_CALLBACK_VAR => $var
|
||||
);
|
||||
|
||||
try {
|
||||
$result = $this->ossClient->completeMultipartUpload($this->bucket, $object, $upload_id, $upload_parts, $options);
|
||||
$this->assertEquals("200", $result['info']['http_code']);
|
||||
$this->assertEquals("{\"Status\":\"OK\"}", $result['body']);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testMultipartUploadCallbackFailed()
|
||||
{
|
||||
$object = "multipart-callback-test.txt";
|
||||
$copiedObject = "multipart-callback-test.txt.copied";
|
||||
$this->ossClient->putObject($this->bucket, $copiedObject, file_get_contents(__FILE__));
|
||||
|
||||
/**
|
||||
* step 1. Initialize a block upload event, which is initialized to upload Multipart, get the upload id
|
||||
*/
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
/*
|
||||
* step 2. uploadPartCopy
|
||||
*/
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* step 3.
|
||||
*/
|
||||
|
||||
$json =
|
||||
'{
|
||||
"callbackUrl":"www.baidu.com",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"{\"mimeType\":${mimeType},\"size\":${size},\"x:var1\":${x:var1},\"x:var2\":${x:var2}}",
|
||||
"callbackBodyType":"application/json"
|
||||
}';
|
||||
|
||||
$var =
|
||||
'{
|
||||
"x:var1":"value1",
|
||||
"x:var2":"值2"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $json,
|
||||
OssClient::OSS_CALLBACK_VAR => $var
|
||||
);
|
||||
|
||||
try {
|
||||
$result = $this->ossClient->completeMultipartUpload($this->bucket, $object, $upload_id, $upload_parts, $options);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(true);
|
||||
$this->assertEquals("203", $e->getHTTPStatus());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testPutObjectCallbackNormal()
|
||||
{
|
||||
//json
|
||||
{
|
||||
$json =
|
||||
'{
|
||||
"callbackUrl":"oss-demo.aliyuncs.com:23450",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"{\"mimeType\":${mimeType},\"size\":${size}}",
|
||||
"callbackBodyType":"application/json"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $json);
|
||||
$this->putObjectCallbackOk($options, "200");
|
||||
}
|
||||
//url
|
||||
{
|
||||
$url =
|
||||
'{
|
||||
"callbackUrl":"oss-demo.aliyuncs.com:23450",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"bucket=${bucket}&object=${object}&etag=${etag}&size=${size}&mimeType=${mimeType}&imageInfo.height=${imageInfo.height}&imageInfo.width=${imageInfo.width}&imageInfo.format=${imageInfo.format}",
|
||||
"callbackBodyType":"application/x-www-form-urlencoded"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $url);
|
||||
$this->putObjectCallbackOk($options, "200");
|
||||
}
|
||||
// Unspecified typre
|
||||
{
|
||||
$url =
|
||||
'{
|
||||
"callbackUrl":"oss-demo.aliyuncs.com:23450",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"bucket=${bucket}&object=${object}&etag=${etag}&size=${size}&mimeType=${mimeType}&imageInfo.height=${imageInfo.height}&imageInfo.width=${imageInfo.width}&imageInfo.format=${imageInfo.format}"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $url);
|
||||
$this->putObjectCallbackOk($options, "200");
|
||||
}
|
||||
//json and body is chinese
|
||||
{
|
||||
$json =
|
||||
'{
|
||||
"callbackUrl":"oss-demo.aliyuncs.com:23450",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"{\" 春水碧于天,画船听雨眠。\":\"垆边人似月,皓腕凝霜雪。\"}",
|
||||
"callbackBodyType":"application/json"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $json);
|
||||
$this->putObjectCallbackOk($options, "200");
|
||||
}
|
||||
//url and body is chinese
|
||||
{
|
||||
$url =
|
||||
'{
|
||||
"callbackUrl":"oss-demo.aliyuncs.com:23450",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"春水碧于天,画船听雨眠。垆边人似月,皓腕凝霜雪",
|
||||
"callbackBodyType":"application/x-www-form-urlencoded"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $url);
|
||||
$this->putObjectCallbackOk($options, "200");
|
||||
}
|
||||
//json and add callback_var
|
||||
{
|
||||
$json =
|
||||
'{
|
||||
"callbackUrl":"oss-demo.aliyuncs.com:23450",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"{\"mimeType\":${mimeType},\"size\":${size},\"x:var1\":${x:var1},\"x:var2\":${x:var2}}",
|
||||
"callbackBodyType":"application/json"
|
||||
}';
|
||||
|
||||
$var =
|
||||
'{
|
||||
"x:var1":"value1",
|
||||
"x:var2":"aliyun.com"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $json,
|
||||
OssClient::OSS_CALLBACK_VAR => $var
|
||||
);
|
||||
$this->putObjectCallbackOk($options, "200");
|
||||
}
|
||||
//url and add callback_var
|
||||
{
|
||||
$url =
|
||||
'{
|
||||
"callbackUrl":"oss-demo.aliyuncs.com:23450",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"bucket=${bucket}&object=${object}&etag=${etag}&size=${size}&mimeType=${mimeType}&imageInfo.height=${imageInfo.height}&imageInfo.width=${imageInfo.width}&imageInfo.format=${imageInfo.format}&my_var1=${x:var1}&my_var2=${x:var2}",
|
||||
"callbackBodyType":"application/x-www-form-urlencoded"
|
||||
}';
|
||||
$var =
|
||||
'{
|
||||
"x:var1":"value1凌波不过横塘路,但目送,芳",
|
||||
"x:var2":"值2"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $url,
|
||||
OssClient::OSS_CALLBACK_VAR => $var
|
||||
);
|
||||
$this->putObjectCallbackOk($options, "200");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testPutCallbackWithCallbackFailed()
|
||||
{
|
||||
{
|
||||
$json =
|
||||
'{
|
||||
"callbackUrl":"http://www.baidu.com",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"{\"mimeType\":${mimeType},\"size\":${size}}",
|
||||
"callbackBodyType":"application/json"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $json);
|
||||
$this->putObjectCallbackFailed($options, "203");
|
||||
}
|
||||
|
||||
{
|
||||
$url =
|
||||
'{
|
||||
"callbackUrl":"http://www.baidu.com",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"bucket=${bucket}&object=${object}&etag=${etag}&size=${size}&mimeType=${mimeType}&imageInfo.height=${imageInfo.height}&imageInfo.width=${imageInfo.width}&imageInfo.format=${imageInfo.format}&my_var1=${x:var1}&my_var2=${x:var2}",
|
||||
"callbackBodyType":"application/x-www-form-urlencoded"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $url);
|
||||
$this->putObjectCallbackFailed($options, "203");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function putObjectCallbackOk($options, $status)
|
||||
{
|
||||
$object = "oss-php-sdk-callback-test.txt";
|
||||
$content = file_get_contents(__FILE__);
|
||||
try {
|
||||
$result = $this->ossClient->putObject($this->bucket, $object, $content, $options);
|
||||
$this->assertEquals($status, $result['info']['http_code']);
|
||||
$this->assertEquals("{\"Status\":\"OK\"}", $result['body']);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
private function putObjectCallbackFailed($options, $status)
|
||||
{
|
||||
$object = "oss-php-sdk-callback-test.txt";
|
||||
$content = file_get_contents(__FILE__);
|
||||
try {
|
||||
$result = $this->ossClient->putObject($this->bucket, $object, $content, $options);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals($status, $e->getHTTPStatus());
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
77
vendor/oss-sdk/tests/OSS/Tests/CnameConfigTest.php
vendored
Executable file
77
vendor/oss-sdk/tests/OSS/Tests/CnameConfigTest.php
vendored
Executable file
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
70
vendor/oss-sdk/tests/OSS/Tests/Common.php
vendored
Executable file
70
vendor/oss-sdk/tests/OSS/Tests/Common.php
vendored
Executable file
@ -0,0 +1,70 @@
|
||||
<?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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
133
vendor/oss-sdk/tests/OSS/Tests/ContentTypeTest.php
vendored
Executable file
133
vendor/oss-sdk/tests/OSS/Tests/ContentTypeTest.php
vendored
Executable file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
class ContentTypeTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
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 = Common::getOssClient();
|
||||
$headers = $client->getObjectMeta($bucket, $object);
|
||||
return $headers['content-type'];
|
||||
}
|
||||
|
||||
public function testByFileName()
|
||||
{
|
||||
$client = Common::getOssClient();
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
$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 = Common::getOssClient();
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
$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 = Common::getOssClient();
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
52
vendor/oss-sdk/tests/OSS/Tests/CopyObjectResult.php
vendored
Executable file
52
vendor/oss-sdk/tests/OSS/Tests/CopyObjectResult.php
vendored
Executable file
@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
140
vendor/oss-sdk/tests/OSS/Tests/CorsConfigTest.php
vendored
Executable file
140
vendor/oss-sdk/tests/OSS/Tests/CorsConfigTest.php
vendored
Executable file
@ -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));
|
||||
}
|
||||
}
|
38
vendor/oss-sdk/tests/OSS/Tests/ExistResultTest.php
vendored
Executable file
38
vendor/oss-sdk/tests/OSS/Tests/ExistResultTest.php
vendored
Executable file
@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
67
vendor/oss-sdk/tests/OSS/Tests/GetCorsResultTest.php
vendored
Executable file
67
vendor/oss-sdk/tests/OSS/Tests/GetCorsResultTest.php
vendored
Executable file
@ -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 {
|
||||
new GetCorsResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
59
vendor/oss-sdk/tests/OSS/Tests/GetLifecycleResultTest.php
vendored
Executable file
59
vendor/oss-sdk/tests/OSS/Tests/GetLifecycleResultTest.php
vendored
Executable file
@ -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 {
|
||||
new GetLifecycleResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
51
vendor/oss-sdk/tests/OSS/Tests/GetLoggingResultTest.php
vendored
Executable file
51
vendor/oss-sdk/tests/OSS/Tests/GetLoggingResultTest.php
vendored
Executable file
@ -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 {
|
||||
new GetLoggingResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
51
vendor/oss-sdk/tests/OSS/Tests/GetRefererResultTest.php
vendored
Executable file
51
vendor/oss-sdk/tests/OSS/Tests/GetRefererResultTest.php
vendored
Executable file
@ -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 {
|
||||
new GetRefererResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
50
vendor/oss-sdk/tests/OSS/Tests/GetWebsiteResultTest.php
vendored
Executable file
50
vendor/oss-sdk/tests/OSS/Tests/GetWebsiteResultTest.php
vendored
Executable file
@ -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 {
|
||||
new GetWebsiteResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
23
vendor/oss-sdk/tests/OSS/Tests/HeaderResultTest.php
vendored
Executable file
23
vendor/oss-sdk/tests/OSS/Tests/HeaderResultTest.php
vendored
Executable file
@ -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');
|
||||
}
|
||||
}
|
77
vendor/oss-sdk/tests/OSS/Tests/HttpTest.php
vendored
Executable file
77
vendor/oss-sdk/tests/OSS/Tests/HttpTest.php
vendored
Executable file
@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
47
vendor/oss-sdk/tests/OSS/Tests/InitiateMultipartUploadResultTest.php
vendored
Executable file
47
vendor/oss-sdk/tests/OSS/Tests/InitiateMultipartUploadResultTest.php
vendored
Executable file
@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
130
vendor/oss-sdk/tests/OSS/Tests/LifecycleConfigTest.php
vendored
Executable file
130
vendor/oss-sdk/tests/OSS/Tests/LifecycleConfigTest.php
vendored
Executable file
@ -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));
|
||||
}
|
||||
}
|
97
vendor/oss-sdk/tests/OSS/Tests/ListBucketsResultTest.php
vendored
Executable file
97
vendor/oss-sdk/tests/OSS/Tests/ListBucketsResultTest.php
vendored
Executable file
@ -0,0 +1,97 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
114
vendor/oss-sdk/tests/OSS/Tests/ListMultipartUploadResultTest.php
vendored
Executable file
114
vendor/oss-sdk/tests/OSS/Tests/ListMultipartUploadResultTest.php
vendored
Executable file
@ -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());
|
||||
}
|
||||
}
|
151
vendor/oss-sdk/tests/OSS/Tests/ListObjectsResultTest.php
vendored
Executable file
151
vendor/oss-sdk/tests/OSS/Tests/ListObjectsResultTest.php
vendored
Executable file
@ -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());
|
||||
}
|
||||
}
|
62
vendor/oss-sdk/tests/OSS/Tests/ListPartsResultTest.php
vendored
Executable file
62
vendor/oss-sdk/tests/OSS/Tests/ListPartsResultTest.php
vendored
Executable file
@ -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());
|
||||
}
|
||||
}
|
249
vendor/oss-sdk/tests/OSS/Tests/LiveChannelXmlTest.php
vendored
Executable file
249
vendor/oss-sdk/tests/OSS/Tests/LiveChannelXmlTest.php
vendored
Executable file
@ -0,0 +1,249 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\Model\LiveChannelInfo;
|
||||
use OSS\Model\LiveChannelListInfo;
|
||||
use OSS\Model\LiveChannelConfig;
|
||||
use OSS\Model\GetLiveChannelStatus;
|
||||
use OSS\Model\GetLiveChannelHistory;
|
||||
|
||||
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 testLiveChannelHistory()
|
||||
{
|
||||
$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]);
|
||||
}
|
||||
|
||||
}
|
47
vendor/oss-sdk/tests/OSS/Tests/LoggingConfigTest.php
vendored
Executable file
47
vendor/oss-sdk/tests/OSS/Tests/LoggingConfigTest.php
vendored
Executable file
@ -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));
|
||||
}
|
||||
}
|
13
vendor/oss-sdk/tests/OSS/Tests/MimeTypesTest.php
vendored
Executable file
13
vendor/oss-sdk/tests/OSS/Tests/MimeTypesTest.php
vendored
Executable file
@ -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'));
|
||||
}
|
||||
}
|
28
vendor/oss-sdk/tests/OSS/Tests/ObjectAclTest.php
vendored
Executable file
28
vendor/oss-sdk/tests/OSS/Tests/ObjectAclTest.php
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
class ObjectAclTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetSet()
|
||||
{
|
||||
$client = Common::getOssClient();
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
84
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketCorsTest.php
vendored
Executable file
84
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketCorsTest.php
vendored
Executable file
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
57
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketLifecycleTest.php
vendored
Executable file
57
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketLifecycleTest.php
vendored
Executable file
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
43
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketLoggingTest.php
vendored
Executable file
43
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketLoggingTest.php
vendored
Executable file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
48
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketRefererTest.php
vendored
Executable file
48
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketRefererTest.php
vendored
Executable file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
56
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketStorageCapacityTest.php
vendored
Executable file
56
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketStorageCapacityTest.php
vendored
Executable file
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
113
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketTest.php
vendored
Executable file
113
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketTest.php
vendored
Executable file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
|
||||
class OssClientBucketTest extends TestOssClientBase
|
||||
{
|
||||
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), 'oss-us-west-1');
|
||||
|
||||
$res = $this->ossClient->getBucketMeta($this->bucket);
|
||||
$this->assertEquals('200', $res['info']['http_code']);
|
||||
$this->assertEquals('oss-us-west-1', $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 setUp()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
46
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketWebsiteTest.php
vendored
Executable file
46
vendor/oss-sdk/tests/OSS/Tests/OssClientBucketWebsiteTest.php
vendored
Executable file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
100
vendor/oss-sdk/tests/OSS/Tests/OssClientImageTest.php
vendored
Executable file
100
vendor/oss-sdk/tests/OSS/Tests/OssClientImageTest.php
vendored
Executable file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
|
||||
class OssClinetImageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $bucketName;
|
||||
private $client;
|
||||
private $local_file;
|
||||
private $object;
|
||||
private $download_file;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->client = Common::getOssClient();
|
||||
$this->bucketName = 'php-sdk-test-bucket-image-' . strval(rand(0, 10000));
|
||||
$this->client->createBucket($this->bucketName);
|
||||
Common::waitMetaSync();
|
||||
$this->local_file = "example.jpg";
|
||||
$this->object = "oss-example.jpg";
|
||||
$this->download_file = "image.jpg";
|
||||
|
||||
$this->client->uploadFile($this->bucketName, $this->object, $this->local_file);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->client->deleteObject($this->bucketName, $this->object);
|
||||
$this->client->deleteBucket($this->bucketName);
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
313
vendor/oss-sdk/tests/OSS/Tests/OssClientMultipartUploadTest.php
vendored
Executable file
313
vendor/oss-sdk/tests/OSS/Tests/OssClientMultipartUploadTest.php
vendored
Executable file
@ -0,0 +1,313 @@
|
||||
<?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__));
|
||||
/**
|
||||
* step 1. 初始化一个分块上传事件, 也就是初始化上传Multipart, 获取upload id
|
||||
*/
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
/*
|
||||
* step 2. uploadPartCopy
|
||||
*/
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* step 3.
|
||||
*/
|
||||
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 testAbortMultipartUpload()
|
||||
{
|
||||
$object = "mpu/multipart-test.txt";
|
||||
/**
|
||||
* step 1. 初始化一个分块上传事件, 也就是初始化上传Multipart, 获取upload id
|
||||
*/
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
/*
|
||||
* step 2. 上传分片
|
||||
*/
|
||||
$part_size = 10 * 1024 * 1024;
|
||||
$upload_file = __FILE__;
|
||||
$upload_filesize = 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);
|
||||
}
|
||||
$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, $options);
|
||||
$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";
|
||||
/**
|
||||
* step 1. 初始化一个分块上传事件, 也就是初始化上传Multipart, 获取upload id
|
||||
*/
|
||||
try {
|
||||
$upload_id = $this->ossClient->initiateMultipartUpload($this->bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
/*
|
||||
* step 2. 上传分片
|
||||
*/
|
||||
$part_size = 10 * 1024 * 1024;
|
||||
$upload_file = __FILE__;
|
||||
$upload_filesize = 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);
|
||||
} 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);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testListMultipartUploads()
|
||||
{
|
||||
$options = null;
|
||||
try {
|
||||
$listMultipartUploadInfo = $this->ossClient->listMultipartUploads($this->bucket, $options);
|
||||
$this->assertNotNull($listMultipartUploadInfo);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
}
|
588
vendor/oss-sdk/tests/OSS/Tests/OssClientObjectTest.php
vendored
Executable file
588
vendor/oss-sdk/tests/OSS/Tests/OssClientObjectTest.php
vendored
Executable file
@ -0,0 +1,588 @@
|
||||
<?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-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);
|
||||
}
|
||||
|
||||
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[1], $result[0]);
|
||||
$this->assertEquals($list[0], $result[1]);
|
||||
|
||||
$result = $this->ossClient->deleteObjects($this->bucket, $list, array('quiet' => 'true'));
|
||||
$this->assertEquals(array(), $result);
|
||||
$this->assertFalse($this->ossClient->doesObjectExist($this->bucket, $object2));
|
||||
} 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);
|
||||
$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 the upload of local files
|
||||
*/
|
||||
try {
|
||||
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, 0);
|
||||
$this->assertEquals($position, filesize(__FILE__));
|
||||
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, $position);
|
||||
$this->assertEquals($position, 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, filesize(__FILE__));
|
||||
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, $position, $options);
|
||||
$this->assertEquals($position, 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 setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->ossClient->putObject($this->bucket, 'oss-php-sdk-test/upload-test-object-name.txt', file_get_contents(__FILE__));
|
||||
}
|
||||
}
|
96
vendor/oss-sdk/tests/OSS/Tests/OssClientRestoreObjectTest.php
vendored
Executable file
96
vendor/oss-sdk/tests/OSS/Tests/OssClientRestoreObjectTest.php
vendored
Executable file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
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 setUp()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
111
vendor/oss-sdk/tests/OSS/Tests/OssClientSignatureTest.php
vendored
Executable file
111
vendor/oss-sdk/tests/OSS/Tests/OssClientSignatureTest.php
vendored
Executable file
@ -0,0 +1,111 @@
|
||||
<?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(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 tearDown()
|
||||
{
|
||||
$this->ossClient->deleteObject($this->bucket, "a.file");
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
216
vendor/oss-sdk/tests/OSS/Tests/OssClientTest.php
vendored
Executable file
216
vendor/oss-sdk/tests/OSS/Tests/OssClientTest.php
vendored
Executable file
@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
|
||||
class OssClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
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");
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct6()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "https://123.123.123.1");
|
||||
$this->assertTrue($ossClient->isUseSSL());
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstrunct7()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient('id', 'key', "http://123.123.123.1");
|
||||
$this->assertFalse($ossClient->isUseSSL());
|
||||
} 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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testSupportPutEmptyObject()
|
||||
{
|
||||
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->putObject($bucket,'test_emptybody','');
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCreateObjectDir()
|
||||
{
|
||||
try {
|
||||
$accessKeyId = ' ' . getenv('OSS_ACCESS_KEY_ID') . ' ';
|
||||
$accessKeySecret = ' ' . getenv('OSS_ACCESS_KEY_SECRET') . ' ';
|
||||
$endpoint = ' ' . getenv('OSS_ENDPOINT') . '/ ';
|
||||
$bucket = getenv('OSS_BUCKET');
|
||||
$object='test-dir';
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false);
|
||||
$ossClient->createObjectDir($bucket,$object);
|
||||
} catch (OssException $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);
|
||||
} 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 = getenv('OSS_BUCKET');
|
||||
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false);
|
||||
$ossClient->getBucketCname($bucket);
|
||||
} 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));
|
||||
}
|
||||
|
||||
}
|
19
vendor/oss-sdk/tests/OSS/Tests/OssExceptionTest.php
vendored
Executable file
19
vendor/oss-sdk/tests/OSS/Tests/OssExceptionTest.php
vendored
Executable file
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
225
vendor/oss-sdk/tests/OSS/Tests/OssUtilTest.php
vendored
Executable file
225
vendor/oss-sdk/tests/OSS/Tests/OssUtilTest.php
vendored
Executable file
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Core\OssUtil;
|
||||
use OSS\OssClient;
|
||||
|
||||
class OssUtilTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testIsChinese()
|
||||
{
|
||||
$this->assertEquals(OssUtil::chkChinese("hello,world"), 0);
|
||||
$str = '你好,这里是卖咖啡!';
|
||||
$strGBK = OssUtil::encodePath($str);
|
||||
$this->assertEquals(OssUtil::chkChinese($str), 1);
|
||||
$this->assertEquals(OssUtil::chkChinese($strGBK), 1);
|
||||
}
|
||||
|
||||
public function testIsGB2312()
|
||||
{
|
||||
$str = '你好,这里是卖咖啡!';
|
||||
$this->assertFalse(OssUtil::isGb2312($str));
|
||||
}
|
||||
|
||||
public function testCheckChar()
|
||||
{
|
||||
$str = '你好,这里是卖咖啡!';
|
||||
$this->assertFalse(OssUtil::checkChar($str));
|
||||
$this->assertTrue(OssUtil::checkChar(iconv("UTF-8", "GB2312//IGNORE", $str)));
|
||||
}
|
||||
|
||||
public function testIsIpFormat()
|
||||
{
|
||||
$this->assertTrue(OssUtil::isIPFormat("10.101.160.147"));
|
||||
$this->assertTrue(OssUtil::isIPFormat("12.12.12.34"));
|
||||
$this->assertTrue(OssUtil::isIPFormat("12.12.12.12"));
|
||||
$this->assertTrue(OssUtil::isIPFormat("255.255.255.255"));
|
||||
$this->assertTrue(OssUtil::isIPFormat("0.1.1.1"));
|
||||
$this->assertFalse(OssUtil::isIPFormat("0.1.1.x"));
|
||||
$this->assertFalse(OssUtil::isIPFormat("0.1.1.256"));
|
||||
$this->assertFalse(OssUtil::isIPFormat("256.1.1.1"));
|
||||
$this->assertFalse(OssUtil::isIPFormat("0.1.1.0.1"));
|
||||
$this->assertTrue(OssUtil::isIPFormat("10.10.10.10:123"));
|
||||
}
|
||||
|
||||
public function testToQueryString()
|
||||
{
|
||||
$option = array("a" => "b");
|
||||
$this->assertEquals('a=b', OssUtil::toQueryString($option));
|
||||
}
|
||||
|
||||
public function testSReplace()
|
||||
{
|
||||
$str = "<>&'\"";
|
||||
$this->assertEquals("&lt;&gt;&'"", OssUtil::sReplace($str));
|
||||
}
|
||||
|
||||
public function testCheckChinese()
|
||||
{
|
||||
$str = '你好,这里是卖咖啡!';
|
||||
$this->assertEquals(OssUtil::chkChinese($str), 1);
|
||||
if (OssUtil::isWin()) {
|
||||
$strGB = OssUtil::encodePath($str);
|
||||
$this->assertEquals($str, iconv("GB2312", "UTF-8", $strGB));
|
||||
}
|
||||
}
|
||||
|
||||
public function testValidateOption()
|
||||
{
|
||||
$option = 'string';
|
||||
|
||||
try {
|
||||
OssUtil::validateOptions($option);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals("string:option must be array", $e->getMessage());
|
||||
}
|
||||
|
||||
$option = null;
|
||||
|
||||
try {
|
||||
OssUtil::validateOptions($option);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testCreateDeleteObjectsXmlBody()
|
||||
{
|
||||
$xml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?><Delete><Quiet>true</Quiet><Object><Key>obj1</Key></Object></Delete>
|
||||
BBBB;
|
||||
$a = array('obj1');
|
||||
$this->assertEquals($xml, $this->cleanXml(OssUtil::createDeleteObjectsXmlBody($a, 'true')));
|
||||
}
|
||||
|
||||
public function testCreateCompleteMultipartUploadXmlBody()
|
||||
{
|
||||
$xml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?><CompleteMultipartUpload><Part><PartNumber>2</PartNumber><ETag>xx</ETag></Part></CompleteMultipartUpload>
|
||||
BBBB;
|
||||
$a = array(array("PartNumber" => 2, "ETag" => "xx"));
|
||||
$this->assertEquals($this->cleanXml(OssUtil::createCompleteMultipartUploadXmlBody($a)), $xml);
|
||||
}
|
||||
|
||||
public function testCreateBucketXmlBody()
|
||||
{
|
||||
$xml = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?><CreateBucketConfiguration><StorageClass>Standard</StorageClass></CreateBucketConfiguration>
|
||||
BBBB;
|
||||
$storageClass ="Standard";
|
||||
$this->assertEquals($this->cleanXml(OssUtil::createBucketXmlBody($storageClass)), $xml);
|
||||
}
|
||||
|
||||
public function testValidateBucket()
|
||||
{
|
||||
$this->assertTrue(OssUtil::validateBucket("xxx"));
|
||||
$this->assertFalse(OssUtil::validateBucket("XXXqwe123"));
|
||||
$this->assertFalse(OssUtil::validateBucket("XX"));
|
||||
$this->assertFalse(OssUtil::validateBucket("/X"));
|
||||
$this->assertFalse(OssUtil::validateBucket(""));
|
||||
}
|
||||
|
||||
public function testValidateObject()
|
||||
{
|
||||
$this->assertTrue(OssUtil::validateObject("xxx"));
|
||||
$this->assertTrue(OssUtil::validateObject("xxx23"));
|
||||
$this->assertTrue(OssUtil::validateObject("12321-xxx"));
|
||||
$this->assertTrue(OssUtil::validateObject("x"));
|
||||
$this->assertFalse(OssUtil::validateObject("/aa"));
|
||||
$this->assertFalse(OssUtil::validateObject("\\aa"));
|
||||
$this->assertFalse(OssUtil::validateObject(""));
|
||||
}
|
||||
|
||||
public function testStartWith()
|
||||
{
|
||||
$this->assertTrue(OssUtil::startsWith("xxab", "xx"), true);
|
||||
}
|
||||
|
||||
public function testReadDir()
|
||||
{
|
||||
$list = OssUtil::readDir("./src", ".|..|.svn|.git", true);
|
||||
$this->assertNotNull($list);
|
||||
}
|
||||
|
||||
public function testIsWin()
|
||||
{
|
||||
//$this->assertTrue(OssUtil::isWin());
|
||||
}
|
||||
|
||||
public function testGetMd5SumForFile()
|
||||
{
|
||||
$this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, filesize(__FILE__) - 1), base64_encode(md5(file_get_contents(__FILE__), true)));
|
||||
}
|
||||
|
||||
public function testGenerateFile()
|
||||
{
|
||||
$path = __DIR__ . DIRECTORY_SEPARATOR . "generatedFile.txt";
|
||||
OssUtil::generateFile($path, 1024 * 1024);
|
||||
$this->assertEquals(filesize($path), 1024 * 1024);
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
public function testThrowOssExceptionWithMessageIfEmpty()
|
||||
{
|
||||
$null = null;
|
||||
try {
|
||||
OssUtil::throwOssExceptionWithMessageIfEmpty($null, "xx");
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('xx', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testThrowOssExceptionWithMessageIfEmpty2()
|
||||
{
|
||||
$null = "";
|
||||
try {
|
||||
OssUtil::throwOssExceptionWithMessageIfEmpty($null, "xx");
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('xx', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testValidContent()
|
||||
{
|
||||
$null = "";
|
||||
try {
|
||||
OssUtil::validateContent($null);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('http body content is invalid', $e->getMessage());
|
||||
}
|
||||
|
||||
$notnull = "x";
|
||||
try {
|
||||
OssUtil::validateContent($notnull);
|
||||
$this->assertTrue(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('http body content is invalid', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testThrowOssExceptionWithMessageIfEmpty3()
|
||||
{
|
||||
$null = "xx";
|
||||
try {
|
||||
OssUtil::throwOssExceptionWithMessageIfEmpty($null, "xx");
|
||||
$this->assertTrue(True);
|
||||
} catch (OssException $e) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
|
||||
}
|
66
vendor/oss-sdk/tests/OSS/Tests/PutSetDeleteResultTest.php
vendored
Executable file
66
vendor/oss-sdk/tests/OSS/Tests/PutSetDeleteResultTest.php
vendored
Executable file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Result\PutSetDeleteResult;
|
||||
|
||||
class ResultTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testNullResponse()
|
||||
{
|
||||
$response = null;
|
||||
try {
|
||||
new PutSetDeleteResult($response);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('raw response is null', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testOkResponse()
|
||||
{
|
||||
$header= array(
|
||||
'x-oss-request-id' => '582AA51E004C4550BD27E0E4',
|
||||
'etag' => '595FA1EA77945233921DF12427F9C7CE',
|
||||
'content-md5' => 'WV+h6neUUjOSHfEkJ/nHzg==',
|
||||
'info' => array(
|
||||
'http_code' => '200',
|
||||
'method' => 'PUT'
|
||||
),
|
||||
);
|
||||
$response = new ResponseCore($header, "this is a mock body, just for test", 200);
|
||||
$result = new PutSetDeleteResult($response);
|
||||
$data = $result->getData();
|
||||
$this->assertTrue($result->isOK());
|
||||
$this->assertEquals("this is a mock body, just for test", $data['body']);
|
||||
$this->assertEquals('582AA51E004C4550BD27E0E4', $data['x-oss-request-id']);
|
||||
$this->assertEquals('595FA1EA77945233921DF12427F9C7CE', $data['etag']);
|
||||
$this->assertEquals('WV+h6neUUjOSHfEkJ/nHzg==', $data['content-md5']);
|
||||
$this->assertEquals('200', $data['info']['http_code']);
|
||||
$this->assertEquals('PUT', $data['info']['method']);
|
||||
}
|
||||
|
||||
public function testFailResponse()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 301);
|
||||
try {
|
||||
new PutSetDeleteResult($response);
|
||||
$this->assertFalse(true);
|
||||
} catch (OssException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
54
vendor/oss-sdk/tests/OSS/Tests/RefererConfigTest.php
vendored
Executable file
54
vendor/oss-sdk/tests/OSS/Tests/RefererConfigTest.php
vendored
Executable file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Model\RefererConfig;
|
||||
|
||||
class RefererConfigTest 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;
|
||||
|
||||
private $validXml2 = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RefererConfiguration>
|
||||
<AllowEmptyReferer>true</AllowEmptyReferer>
|
||||
<RefererList>
|
||||
<Referer>http://www.aliyun.com</Referer>
|
||||
</RefererList>
|
||||
</RefererConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$refererConfig = new RefererConfig();
|
||||
$refererConfig->parseFromXml($this->validXml);
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($refererConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
public function testParseValidXml2()
|
||||
{
|
||||
$refererConfig = new RefererConfig();
|
||||
$refererConfig->parseFromXml($this->validXml2);
|
||||
$this->assertEquals(true, $refererConfig->isAllowEmptyReferer());
|
||||
$this->assertEquals(1, count($refererConfig->getRefererList()));
|
||||
$this->assertEquals($this->cleanXml($this->validXml2), $this->cleanXml(strval($refererConfig)));
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
}
|
59
vendor/oss-sdk/tests/OSS/Tests/StorageCapacityTest.php
vendored
Executable file
59
vendor/oss-sdk/tests/OSS/Tests/StorageCapacityTest.php
vendored
Executable file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\Model\StorageCapacityConfig;
|
||||
use OSS\Result\GetStorageCapacityResult;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
class StorageCapacityTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
private $inValidXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<BucketUserQos>
|
||||
<OssStorageCapacity>1</OssStorageCapacity>
|
||||
</BucketUserQos>
|
||||
BBBB;
|
||||
|
||||
private $validXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<BucketUserQos>
|
||||
<StorageCapacity>1</StorageCapacity>
|
||||
</BucketUserQos>
|
||||
BBBB;
|
||||
|
||||
public function testParseInValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->inValidXml, 300);
|
||||
try {
|
||||
new GetStorageCapacityResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {}
|
||||
}
|
||||
|
||||
public function testParseEmptyXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), "", 300);
|
||||
try {
|
||||
new GetStorageCapacityResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {}
|
||||
}
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$response = new ResponseCore(array(), $this->validXml, 200);
|
||||
$result = new GetStorageCapacityResult($response);
|
||||
$this->assertEquals($result->getData(), 1);
|
||||
}
|
||||
|
||||
public function testSerializeToXml()
|
||||
{
|
||||
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<BucketUserQos><StorageCapacity>1</StorageCapacity></BucketUserQos>\n";
|
||||
|
||||
$storageCapacityConfig = new StorageCapacityConfig(1);
|
||||
$content = $storageCapacityConfig->serializeToXml();
|
||||
$this->assertEquals($content, $xml);
|
||||
}
|
||||
}
|
74
vendor/oss-sdk/tests/OSS/Tests/SymlinkTest.php
vendored
Executable file
74
vendor/oss-sdk/tests/OSS/Tests/SymlinkTest.php
vendored
Executable file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Result\SymlinkResult;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php';
|
||||
|
||||
class SymlinkTest extends TestOssClientBase
|
||||
{
|
||||
public function testPutSymlink()
|
||||
{
|
||||
$bucket = getenv('OSS_BUCKET');
|
||||
$symlink = 'test-link';
|
||||
$special_object = 'exist_object^$#!~';
|
||||
$object = 'exist_object';
|
||||
|
||||
$this->ossClient ->putObject($bucket, $object, 'test_content');
|
||||
$this->ossClient->putSymlink($bucket, $symlink, $object);
|
||||
$result = $this->ossClient->getObject($bucket, $symlink);
|
||||
$this->assertEquals('test_content', $result);
|
||||
|
||||
$this->ossClient ->putObject($bucket, $special_object, 'test_content');
|
||||
$this->ossClient->putSymlink($bucket, $symlink, $special_object);
|
||||
$result = $this->ossClient->getObject($bucket, $symlink);
|
||||
$this->assertEquals('test_content', $result);
|
||||
}
|
||||
|
||||
public function testGetSymlink()
|
||||
{
|
||||
$bucket = getenv('OSS_BUCKET');
|
||||
$symlink = 'test-link';
|
||||
$object = 'exist_object^$#!~';
|
||||
|
||||
$result = $this->ossClient->getSymlink($bucket, $symlink);
|
||||
$this->assertEquals($result[OssClient::OSS_SYMLINK_TARGET], $object);
|
||||
$this->assertEquals('200', $result[OssClient::OSS_INFO][OssClient::OSS_HTTP_CODE]);
|
||||
$this->assertTrue(isset($result[OssClient::OSS_ETAG]));
|
||||
$this->assertTrue(isset($result[OssClient::OSS_REQUEST_ID]));
|
||||
}
|
||||
|
||||
public function testPutNullSymlink()
|
||||
{
|
||||
$bucket = getenv('OSS_BUCKET');
|
||||
$symlink = 'null-link';
|
||||
$object_not_exist = 'not_exist_object+$#!b不';
|
||||
$this->ossClient->putSymlink($bucket, $symlink, $object_not_exist);
|
||||
|
||||
try{
|
||||
$this->ossClient->getObject($bucket, $symlink);
|
||||
$this->assertTrue(false);
|
||||
}catch (OssException $e){
|
||||
$this->assertEquals('The symlink target object does not exist', $e->getErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetNullSymlink()
|
||||
{
|
||||
$bucket = getenv('OSS_BUCKET');
|
||||
$symlink = 'null-link-new';
|
||||
|
||||
try{
|
||||
$result = $this->ossClient->getSymlink($bucket, $symlink);
|
||||
$this->assertTrue(false);
|
||||
}catch (OssException $e){
|
||||
$this->assertEquals('The specified key does not exist.', $e->getErrorMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
51
vendor/oss-sdk/tests/OSS/Tests/TestOssClientBase.php
vendored
Executable file
51
vendor/oss-sdk/tests/OSS/Tests/TestOssClientBase.php
vendored
Executable file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
use OSS\OssClient;
|
||||
|
||||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'Common.php';
|
||||
|
||||
class TestOssClientBase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var OssClient
|
||||
*/
|
||||
protected $ossClient;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $bucket;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->bucket = Common::getBucketName() . rand(100000, 999999);
|
||||
$this->ossClient = Common::getOssClient();
|
||||
$this->ossClient->createBucket($this->bucket);
|
||||
Common::waitMetaSync();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if (!$this->ossClient->doesBucketExist($this->bucket)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$objects = $this->ossClient->listObjects(
|
||||
$this->bucket, array('max-keys' => 1000, 'delimiter' => ''))->getObjectList();
|
||||
$keys = array();
|
||||
foreach ($objects as $obj) {
|
||||
$keys[] = $obj->getKey();
|
||||
}
|
||||
if (count($keys) > 0) {
|
||||
$this->ossClient->deleteObjects($this->bucket, $keys);
|
||||
}
|
||||
$uploads = $this->ossClient->listMultipartUploads($this->bucket)->getUploads();
|
||||
foreach ($uploads as $up) {
|
||||
$this->ossClient->abortMultipartUpload($this->bucket, $up->getKey(), $up->getUploadId());
|
||||
}
|
||||
|
||||
$this->ossClient->deleteBucket($this->bucket);
|
||||
}
|
||||
}
|
33
vendor/oss-sdk/tests/OSS/Tests/UploadPartResultTest.php
vendored
Executable file
33
vendor/oss-sdk/tests/OSS/Tests/UploadPartResultTest.php
vendored
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Result\UploadPartResult;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
class UploadPartResultTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $validHeader = array('etag' => '7265F4D211B56873A381D321F586E4A9');
|
||||
private $invalidHeader = array();
|
||||
|
||||
public function testParseValidHeader()
|
||||
{
|
||||
$response = new ResponseCore($this->validHeader, "", 200);
|
||||
$result = new UploadPartResult($response);
|
||||
$eTag = $result->getData();
|
||||
$this->assertEquals('7265F4D211B56873A381D321F586E4A9', $eTag);
|
||||
}
|
||||
|
||||
public function testParseInvalidHeader()
|
||||
{
|
||||
$response = new ResponseCore($this->invalidHeader, "", 200);
|
||||
try {
|
||||
new UploadPartResult($response);
|
||||
$this->assertTrue(false);
|
||||
} catch (OssException $e) {
|
||||
$this->assertEquals('cannot get ETag', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
56
vendor/oss-sdk/tests/OSS/Tests/WebsiteConfigTest.php
vendored
Executable file
56
vendor/oss-sdk/tests/OSS/Tests/WebsiteConfigTest.php
vendored
Executable file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Tests;
|
||||
|
||||
|
||||
use OSS\Model\WebsiteConfig;
|
||||
|
||||
class WebsiteConfigTest 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;
|
||||
|
||||
private $nullXml = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?><WebsiteConfiguration><IndexDocument><Suffix/></IndexDocument><ErrorDocument><Key/></ErrorDocument></WebsiteConfiguration>
|
||||
BBBB;
|
||||
private $nullXml2 = <<<BBBB
|
||||
<?xml version="1.0" encoding="utf-8"?><WebsiteConfiguration><IndexDocument><Suffix></Suffix></IndexDocument><ErrorDocument><Key></Key></ErrorDocument></WebsiteConfiguration>
|
||||
BBBB;
|
||||
|
||||
public function testParseValidXml()
|
||||
{
|
||||
$websiteConfig = new WebsiteConfig("index");
|
||||
$websiteConfig->parseFromXml($this->validXml);
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($websiteConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
public function testParsenullXml()
|
||||
{
|
||||
$websiteConfig = new WebsiteConfig();
|
||||
$websiteConfig->parseFromXml($this->nullXml);
|
||||
$this->assertTrue($this->cleanXml($this->nullXml) === $this->cleanXml($websiteConfig->serializeToXml()) ||
|
||||
$this->cleanXml($this->nullXml2) === $this->cleanXml($websiteConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
public function testWebsiteConstruct()
|
||||
{
|
||||
$websiteConfig = new WebsiteConfig("index.html", "errorDocument.html");
|
||||
$this->assertEquals('index.html', $websiteConfig->getIndexDocument());
|
||||
$this->assertEquals('errorDocument.html', $websiteConfig->getErrorDocument());
|
||||
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($websiteConfig->serializeToXml()));
|
||||
}
|
||||
|
||||
private function cleanXml($xml)
|
||||
{
|
||||
return str_replace("\n", "", str_replace("\r", "", $xml));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user