初始化代码

This commit is contained in:
2025-12-22 14:32:54 +08:00
parent e27ab90d9f
commit d02b31a8b9
1459 changed files with 240973 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
<?php
// Hack to override the time returned from the S3SignatureV4
// @codingStandardsIgnoreStart
namespace Qiniu {
function time()
{
return isset($_SERVER['override_qiniu_auth_time'])
? 1234567890
: \time();
}
}
namespace Qiniu\Tests {
use Qiniu\Auth;
// @codingStandardsIgnoreEnd
class AuthTest extends \PHPUnit_Framework_TestCase
{
public function testSign()
{
global $dummyAuth;
$token = $dummyAuth->sign('test');
$this->assertEquals('abcdefghklmnopq:mSNBTR7uS2crJsyFr2Amwv1LaYg=', $token);
}
public function testSignWithData()
{
global $dummyAuth;
$token = $dummyAuth->signWithData('test');
$this->assertEquals('abcdefghklmnopq:-jP8eEV9v48MkYiBGs81aDxl60E=:dGVzdA==', $token);
}
public function testSignRequest()
{
global $dummyAuth;
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', '');
$this->assertEquals('abcdefghklmnopq:cFyRVoWrE3IugPIMP5YJFTO-O-Y=', $token);
$ctype = 'application/x-www-form-urlencoded';
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', $ctype);
$this->assertEquals($token, 'abcdefghklmnopq:svWRNcacOE-YMsc70nuIYdaa1e4=');
}
public function testPrivateDownloadUrl()
{
global $dummyAuth;
$_SERVER['override_qiniu_auth_time'] = true;
$url = $dummyAuth->privateDownloadUrl('http://www.qiniu.com?go=1');
$expect = 'http://www.qiniu.com?go=1&e=1234571490&token=abcdefghklmnopq:8vzBeLZ9W3E4kbBLFLW0Xe0u7v4=';
$this->assertEquals($expect, $url);
unset($_SERVER['override_qiniu_auth_time']);
}
public function testUploadToken()
{
global $dummyAuth;
$_SERVER['override_qiniu_auth_time'] = true;
$token = $dummyAuth->uploadToken('1', '2', 3600, array('endUser' => 'y'));
// @codingStandardsIgnoreStart
$exp = 'abcdefghklmnopq:yyeexeUkPOROoTGvwBjJ0F0VLEo=:eyJlbmRVc2VyIjoieSIsInNjb3BlIjoiMToyIiwiZGVhZGxpbmUiOjEyMzQ1NzE0OTB9';
// @codingStandardsIgnoreEnd
$this->assertEquals($exp, $token);
unset($_SERVER['override_qiniu_auth_time']);
}
public function testVerifyCallback()
{
}
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Qiniu\Tests;
use Qiniu;
class Base64Test extends \PHPUnit_Framework_TestCase
{
public function testUrlSafe()
{
$a = '你好';
$b = \Qiniu\base64_urlSafeEncode($a);
$this->assertEquals($a, \Qiniu\base64_urlSafeDecode($b));
}
}

View File

@@ -0,0 +1,227 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Storage\BucketManager;
class BucketTest extends \PHPUnit_Framework_TestCase
{
protected $bucketManager;
protected $dummyBucketManager;
protected $bucketName;
protected $key;
protected $key2;
protected function setUp()
{
global $bucketName;
global $key;
global $key2;
$this->bucketName = $bucketName;
$this->key = $key;
$this->key2 = $key2;
global $testAuth;
$this->bucketManager = new BucketManager($testAuth);
global $dummyAuth;
$this->dummyBucketManager = new BucketManager($dummyAuth);
}
public function testBuckets()
{
list($list, $error) = $this->bucketManager->buckets();
$this->assertTrue(in_array($this->bucketName, $list));
$this->assertNull($error);
list($list2, $error) = $this->dummyBucketManager->buckets();
$this->assertEquals(401, $error->code());
$this->assertNull($list2);
$this->assertNotNull($error->message());
}
public function testList()
{
list($ret, $error) = $this->bucketManager->listFiles($this->bucketName, null, null, 10);
$this->assertNotNull($ret['items'][0]);
$this->assertNotNull($ret['marker']);
}
public function testStat()
{
list($stat, $error) = $this->bucketManager->stat($this->bucketName, $this->key);
$this->assertNotNull($stat);
$this->assertNull($error);
$this->assertNotNull($stat['hash']);
list($stat, $error) = $this->bucketManager->stat($this->bucketName, 'nofile');
$this->assertNull($stat);
$this->assertEquals(612, $error->code());
$this->assertNotNull($error->message());
list($stat, $error) = $this->bucketManager->stat('nobucket', 'nofile');
$this->assertNull($stat);
$this->assertEquals(631, $error->code());
$this->assertNotNull($error->message());
}
public function testDelete()
{
$error = $this->bucketManager->delete($this->bucketName, 'del');
$this->assertEquals(612, $error->code());
}
public function testRename()
{
$key = 'renamefrom' . rand();
$this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key);
$key2 = 'renameto' . $key;
$error = $this->bucketManager->rename($this->bucketName, $key, $key2);
$this->assertNull($error);
$error = $this->bucketManager->delete($this->bucketName, $key2);
$this->assertNull($error);
}
public function testCopy()
{
$key = 'copyto' . rand();
$this->bucketManager->delete($this->bucketName, $key);
$error = $this->bucketManager->copy(
$this->bucketName,
$this->key,
$this->bucketName,
$key
);
$this->assertNull($error);
//test force copy
$error = $this->bucketManager->copy(
$this->bucketName,
$this->key2,
$this->bucketName,
$key,
true
);
$this->assertNull($error);
list($key2Stat,) = $this->bucketManager->stat($this->bucketName, $this->key2);
list($key2CopiedStat,) = $this->bucketManager->stat($this->bucketName, $key);
$this->assertEquals($key2Stat['hash'], $key2CopiedStat['hash']);
$error = $this->bucketManager->delete($this->bucketName, $key);
$this->assertNull($error);
}
public function testChangeMime()
{
$error = $this->bucketManager->changeMime(
$this->bucketName,
'php-sdk.html',
'text/html'
);
$this->assertNull($error);
}
public function testPrefetch()
{
$error = $this->bucketManager->prefetch(
$this->bucketName,
'php-sdk.html'
);
$this->assertNull($error);
}
public function testFetch()
{
list($ret, $error) = $this->bucketManager->fetch(
'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html',
$this->bucketName,
'fetch.html'
);
$this->assertArrayHasKey('hash', $ret);
$this->assertNull($error);
list($ret, $error) = $this->bucketManager->fetch(
'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html',
$this->bucketName,
''
);
$this->assertArrayHasKey('key', $ret);
$this->assertNull($error);
list($ret, $error) = $this->bucketManager->fetch(
'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html',
$this->bucketName
);
$this->assertArrayHasKey('key', $ret);
$this->assertNull($error);
}
public function testBatchCopy()
{
$key = 'copyto' . rand();
$ops = BucketManager::buildBatchCopy(
$this->bucketName,
array($this->key => $key),
$this->bucketName,
true
);
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
$ops = BucketManager::buildBatchDelete($this->bucketName, array($key));
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
}
public function testBatchMove()
{
$key = 'movefrom' . rand();
$this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key);
$key2 = $key . 'to';
$ops = BucketManager::buildBatchMove(
$this->bucketName,
array($key => $key2),
$this->bucketName,
true
);
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
$error = $this->bucketManager->delete($this->bucketName, $key2);
$this->assertNull($error);
}
public function testBatchRename()
{
$key = 'rename' . rand();
$this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key);
$key2 = $key . 'to';
$ops = BucketManager::buildBatchRename($this->bucketName, array($key => $key2), true);
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
$error = $this->bucketManager->delete($this->bucketName, $key2);
$this->assertNull($error);
}
public function testBatchStat()
{
$ops = BucketManager::buildBatchStat($this->bucketName, array('php-sdk.html'));
list($ret, $error) = $this->bucketManager->batch($ops);
$this->assertEquals(200, $ret[0]['code']);
}
public function testDeleteAfterDays()
{
$key = rand();
$err = $this->bucketManager->deleteAfterDays($this->bucketName, $key, 1);
$this->assertEquals(612, $err->code());
$this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key);
$err = $this->bucketManager->deleteAfterDays($this->bucketName, $key, 1);
$this->assertEquals(null, $err);
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: wf
* Date: 2017/6/21
* Time: AM8:46
*/
namespace Qiniu\Tests;
use Qiniu\Cdn\CdnManager;
use Qiniu\Http\Client;
class CdnManagerTest extends \PHPUnit_Framework_TestCase
{
protected $cdnManager;
protected $encryptKey;
protected $imgUrl;
protected function setUp()
{
global $timestampAntiLeechEncryptKey;
global $customDomain;
global $testAuth;
$this->cdnManager = new CdnManager($testAuth);
$this->encryptKey = $timestampAntiLeechEncryptKey;
$this->imgUrl = $customDomain . '/24.jpg';
}
public function testCreateTimestampAntiLeechUrl()
{
$signUrl = $this->cdnManager->createTimestampAntiLeechUrl($this->imgUrl, $this->encryptKey, 3600);
$response = Client::get($signUrl);
$this->assertEquals($response->statusCode, 200);
$this->assertNull($response->error);
$url2 = $this->imgUrl . '?imageInfo';
$signUrl2 = $this->cdnManager->createTimestampAntiLeechUrl($url2, $this->encryptKey, 3600);
$response = Client::get($signUrl2);
$imgInfo = $response->json();
$this->assertEquals($response->statusCode, 200);
$this->assertEquals($imgInfo['size'], 2196145);
$this->assertNull($response->error);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Qiniu\Tests;
use Qiniu;
class Crc32Test extends \PHPUnit_Framework_TestCase
{
public function testData()
{
$a = '你好';
$b = \Qiniu\crc32_data($a);
$this->assertEquals('1352841281', $b);
}
public function testFile()
{
$b = \Qiniu\crc32_file(__file__);
$c = \Qiniu\crc32_file(__file__);
$this->assertEquals($c, $b);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Http\Client;
class DownloadTest extends \PHPUnit_Framework_TestCase
{
public function test()
{
global $testAuth;
$base_url = 'http://private-res.qiniudn.com/gogopher.jpg';
$private_url = $testAuth->privateDownloadUrl($base_url);
$response = Client::get($private_url);
$this->assertEquals(200, $response->statusCode);
}
public function testFop()
{
global $testAuth;
$base_url = 'http://private-res.qiniudn.com/gogopher.jpg?exif';
$private_url = $testAuth->privateDownloadUrl($base_url);
$response = Client::get($private_url);
$this->assertEquals(200, $response->statusCode);
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Etag;
class EtagTest extends \PHPUnit_Framework_TestCase
{
public function test0M()
{
$file = qiniuTempFile(0);
list($r, $error) = Etag::sum($file);
unlink($file);
$this->assertEquals('Fto5o-5ea0sNMlW_75VgGJCv2AcJ', $r);
$this->assertNull($error);
}
public function testLess4M()
{
$file = qiniuTempFile(3 * 1024 * 1024);
list($r, $error) = Etag::sum($file);
unlink($file);
$this->assertEquals('Fs5BpnAjRykYTg6o5E09cjuXrDkG', $r);
$this->assertNull($error);
}
public function test4M()
{
$file = qiniuTempFile(4 * 1024 * 1024);
list($r, $error) = Etag::sum($file);
unlink($file);
$this->assertEquals('FiuKULnybewpEnrfTmxjsxc-3dWp', $r);
$this->assertNull($error);
}
public function testMore4M()
{
$file = qiniuTempFile(5 * 1024 * 1024);
list($r, $error) = Etag::sum($file);
unlink($file);
$this->assertEquals('lhvyfIWMYFTq4s4alzlhXoAkqfVL', $r);
$this->assertNull($error);
}
public function test8M()
{
$file = qiniuTempFile(8 * 1024 * 1024);
list($r, $error) = Etag::sum($file);
unlink($file);
$this->assertEquals('lmRm9ZfGZ86bnMys4wRTWtJj9ClG', $r);
$this->assertNull($error);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Processing\Operation;
use Qiniu\Processing\PersistentFop;
class FopTest extends \PHPUnit_Framework_TestCase
{
public function testExifPub()
{
$fop = new Operation('testres.qiniudn.com');
list($exif, $error) = $fop->execute('gogopher.jpg', 'exif');
$this->assertNull($error);
$this->assertNotNull($exif);
}
public function testExifPrivate()
{
global $testAuth;
$fop = new Operation('private-res.qiniudn.com', $testAuth);
list($exif, $error) = $fop->execute('noexif.jpg', 'exif');
$this->assertNotNull($error);
$this->assertNull($exif);
}
public function testbuildUrl()
{
$fops = 'imageView2/2/h/200';
$fop = new Operation('testres.qiniudn.com');
$url = $fop->buildUrl('gogopher.jpg', $fops);
$this->assertEquals($url, 'http://testres.qiniudn.com/gogopher.jpg?imageView2/2/h/200');
$fops = array('imageView2/2/h/200', 'imageInfo');
$url = $fop->buildUrl('gogopher.jpg', $fops);
$this->assertEquals($url, 'http://testres.qiniudn.com/gogopher.jpg?imageView2/2/h/200|imageInfo');
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Storage\FormUploader;
use Qiniu\Storage\UploadManager;
use Qiniu\Config;
class FormUpTest extends \PHPUnit_Framework_TestCase
{
protected $bucketName;
protected $auth;
protected $cfg;
protected function setUp()
{
global $bucketName;
$this->bucketName = $bucketName;
global $testAuth;
$this->auth = $testAuth;
$this->cfg = new Config();
}
public function testData()
{
$token = $this->auth->uploadToken($this->bucketName);
list($ret, $error) = FormUploader::put($token, 'formput', 'hello world', $this->cfg, null, 'text/plain', null);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
}
public function testData2()
{
$upManager = new UploadManager();
$token = $this->auth->uploadToken($this->bucketName);
list($ret, $error) = $upManager->put($token, 'formput', 'hello world', null, 'text/plain', null);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
}
public function testFile()
{
$key = 'formPutFile';
$token = $this->auth->uploadToken($this->bucketName, $key);
list($ret, $error) = FormUploader::putFile($token, $key, __file__, $this->cfg, null, 'text/plain', null);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
}
public function testFile2()
{
$key = 'formPutFile';
$token = $this->auth->uploadToken($this->bucketName, $key);
$upManager = new UploadManager();
list($ret, $error) = $upManager->putFile($token, $key, __file__, null, 'text/plain', null);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Http\Client;
class HttpTest extends \PHPUnit_Framework_TestCase
{
public function testGet()
{
$response = Client::get('baidu.com');
$this->assertEquals($response->statusCode, 200);
$this->assertNotNull($response->body);
$this->assertNull($response->error);
}
public function testGetQiniu()
{
$response = Client::get('up.qiniu.com');
$this->assertEquals(405, $response->statusCode);
$this->assertNotNull($response->body);
$this->assertNotNull($response->xReqId());
$this->assertNotNull($response->xLog());
$this->assertNotNull($response->error);
}
public function testPost()
{
$response = Client::post('baidu.com', null);
$this->assertEquals($response->statusCode, 200);
$this->assertNotNull($response->body);
$this->assertNull($response->error);
}
public function testPostQiniu()
{
$response = Client::post('up.qiniu.com', null);
$this->assertEquals($response->statusCode, 400);
$this->assertNotNull($response->body);
$this->assertNotNull($response->xReqId());
$this->assertNotNull($response->xLog());
$this->assertNotNull($response->error);
}
}

View File

@@ -0,0 +1,261 @@
<?php
namespace Qiniu\Tests;
/**
* imageprocess test
*
* @package Qiniu
* @subpackage test
* @author Sherlock Ren <sherlock_ren@icloud.com>
*/
class ImageUrlBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* 缩略图测试
*
* @test
* @return void
* @author Sherlock Ren <sherlock_ren@icloud.com>
*/
public function testThumbutl()
{
$imageUrlBuilder = new \Qiniu\Processing\ImageUrlBuilder();
$url = 'http://78re52.com1.z0.glb.clouddn.com/resource/gogopher.jpg';
$url2 = $url . '?watermark/1/gravity/SouthEast/dx/0/dy/0/image/'
. 'aHR0cDovL2Fkcy1jZG4uY2h1Y2h1amllLmNvbS9Ga1R6bnpIY2RLdmRBUFc5cHZZZ3pTc21UY0tB';
// 异常测试
$this->assertEquals($url, $imageUrlBuilder->thumbnail($url, 1, 0, 0));
$this->assertEquals($url, \Qiniu\thumbnail($url, 1, 0, 0));
// 简单缩略测试
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/ignore-error/1/',
$imageUrlBuilder->thumbnail($url, 1, 200, 200)
);
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/ignore-error/1/',
\Qiniu\thumbnail($url, 1, 200, 200)
);
// 输出格式测试
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/ignore-error/1/',
$imageUrlBuilder->thumbnail($url, 1, 200, 200, 'png')
);
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/ignore-error/1/',
\Qiniu\thumbnail($url, 1, 200, 200, 'png')
);
// 渐进显示测试
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/interlace/1/ignore-error/1/',
$imageUrlBuilder->thumbnail($url, 1, 200, 200, 'png', 1)
);
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/ignore-error/1/',
\Qiniu\thumbnail($url, 1, 200, 200, 'png', 2)
);
// 图片质量测试
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/interlace/1/q/80/ignore-error/1/',
$imageUrlBuilder->thumbnail($url, 1, 200, 200, 'png', 1, 80)
);
$this->assertEquals(
$url . '?imageView2/1/w/200/h/200/format/png/interlace/1/ignore-error/1/',
\Qiniu\thumbnail($url, 1, 200, 200, 'png', 1, 101)
);
// 多参数测试
$this->assertEquals(
$url2 . '|imageView2/1/w/200/h/200/ignore-error/1/',
$imageUrlBuilder->thumbnail($url2, 1, 200, 200)
);
$this->assertEquals(
$url2 . '|imageView2/1/w/200/h/200/ignore-error/1/',
\Qiniu\thumbnail($url2, 1, 200, 200)
);
}
/**
* 图片水印测试
*
* @test
* @param void
* @return void
* @author Sherlock Ren <sherlock_ren@icloud.com>
*/
public function waterImgTest()
{
$imageUrlBuilder = new \Qiniu\Processing\ImageUrlBuilder();
$url = 'http://78re52.com1.z0.glb.clouddn.com/resource/gogopher.jpg';
$url2 = $url . '?imageView2/1/w/200/h/200/format/png/ignore-error/1/';
$image = 'http://developer.qiniu.com/resource/logo-2.jpg';
// 水印简单测试
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
$imageUrlBuilder->waterImg($url, $image)
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/gravity/SouthEast/',
$imageUrlBuilder->waterImg($url, $image, 101)
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw==/',
$imageUrlBuilder->waterImg($url, $image, 101, 'sdfsd')
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterImg($url, $image)
);
// 横轴边距测试
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/dx/10/',
$imageUrlBuilder->waterImg($url, $image, 100, 'SouthEast', 10)
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterImg($url, $image, 100, 'SouthEast', 'sad')
);
// 纵轴边距测试
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/dx/10/dy/10/',
$imageUrlBuilder->waterImg($url, $image, 100, 'SouthEast', 10, 10)
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterImg($url, $image, 100, 'SouthEast', 'sad', 'asdf')
);
// 自适应原图的短边比例测试
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/dx/10/dy/10/ws/0.5/',
$imageUrlBuilder->waterImg($url, $image, 100, 'SouthEast', 10, 10, 0.5)
);
$this->assertEquals(
$url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterImg($url, $image, 100, 'SouthEast', 'sad', 'asdf', 2)
);
// 多参数测试
$this->assertEquals(
$url2 . '|watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
$imageUrlBuilder->waterImg($url2, $image)
);
$this->assertEquals(
$url2 . '|watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterImg($url2, $image)
);
}
/**
* 文字水印测试
*
* @test
* @param void
* @return void
* @author Sherlock Ren <sherlock_ren@icloud.com>
*/
public function waterTextTest()
{
$imageUrlBuilder = new \Qiniu\Processing\ImageUrlBuilder();
$url = 'http://78re52.com1.z0.glb.clouddn.com/resource/gogopher.jpg';
$url2 = $url . '?imageView2/1/w/200/h/200/format/png/ignore-error/1/';
$text = '测试一下';
$font = '微软雅黑';
$fontColor = '#FF0000';
// 水印简单测试
$this->assertEquals($url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/'
. 'fontsize/500/dissolve/100/gravity/SouthEast/', $imageUrlBuilder->waterText($url, $text, $font, 500));
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/'
. 'dissolve/100/gravity/SouthEast/',
\Qiniu\waterText($url, $text, $font, 'sdf')
);
// 字体颜色测试
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/'
. 'I0ZGMDAwMA==/dissolve/100/gravity/SouthEast/',
$imageUrlBuilder->waterText($url, $text, $font, 500, $fontColor)
);
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fill/I0ZGMDAwMA=='
. '/dissolve/100/gravity/SouthEast/',
\Qiniu\waterText($url, $text, $font, 'sdf', $fontColor)
);
// 透明度测试
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/I0ZGMDAwMA=='
. '/dissolve/80/gravity/SouthEast/',
$imageUrlBuilder->waterText($url, $text, $font, 500, $fontColor, 80)
);
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fill/I0ZGMDAwMA=='
. '/gravity/SouthEast/',
\Qiniu\waterText($url, $text, $font, 'sdf', $fontColor, 101)
);
// 水印位置测试
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/I0ZGMDAwMA=='
. '/dissolve/80/gravity/East/',
$imageUrlBuilder->waterText($url, $text, $font, 500, $fontColor, 80, 'East')
);
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fill/I0ZGMDAwMA==/',
\Qiniu\waterText($url, $text, $font, 'sdf', $fontColor, 101, 'sdfsdf')
);
// 横轴距离测试
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/I0ZGMDAwMA=='
. '/dissolve/80/gravity/East/dx/10/',
$imageUrlBuilder->waterText($url, $text, $font, 500, $fontColor, 80, 'East', 10)
);
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fill/I0ZGMDAwMA==/',
\Qiniu\waterText($url, $text, $font, 'sdf', $fontColor, 101, 'sdfsdf', 'sdfs')
);
// 纵轴距离测试
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/I0ZGMDAwMA=='
. '/dissolve/80/gravity/East/dx/10/dy/10/',
$imageUrlBuilder->waterText($url, $text, $font, 500, $fontColor, 80, 'East', 10, 10)
);
$this->assertEquals(
$url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fill/I0ZGMDAwMA==/',
\Qiniu\waterText($url, $text, $font, 'sdf', $fontColor, 101, 'sdfsdf', 'sdfs', 'ssdf')
);
// 多参数测试
$this->assertEquals(
$url2 . '|watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/'
. 'fontsize/500/dissolve/100/gravity/SouthEast/',
$imageUrlBuilder->waterText($url2, $text, $font, 500)
);
$this->assertEquals(
$url2 . '|watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/'
. 'fontsize/500/dissolve/100/gravity/SouthEast/',
\Qiniu\waterText($url2, $text, $font, 500)
);
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Processing\Operation;
use Qiniu\Processing\PersistentFop;
class PfopTest extends \PHPUnit_Framework_TestCase
{
public function testPfop()
{
global $testAuth;
$bucket = 'testres';
$key = 'sintel_trailer.mp4';
$pfop = new PersistentFop($testAuth, null);
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240';
list($id, $error) = $pfop->execute($bucket, $key, $fops);
$this->assertNull($error);
list($status, $error) = $pfop->status($id);
$this->assertNotNull($status);
$this->assertNull($error);
}
public function testPfops()
{
global $testAuth;
$bucket = 'testres';
$key = 'sintel_trailer.mp4';
$fops = array(
'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240',
'vframe/jpg/offset/7/w/480/h/360',
);
$pfop = new PersistentFop($testAuth, null);
list($id, $error) = $pfop->execute($bucket, $key, $fops);
$this->assertNull($error);
list($status, $error) = $pfop->status($id);
$this->assertNotNull($status);
$this->assertNull($error);
}
public function testMkzip()
{
global $testAuth;
$bucket = 'phpsdk';
$key = 'php-logo.png';
$pfop = new PersistentFop($testAuth, null);
$url1 = 'http://phpsdk.qiniudn.com/php-logo.png';
$url2 = 'http://phpsdk.qiniudn.com/php-sdk.html';
$zipKey = 'test.zip';
$fops = 'mkzip/2/url/' . \Qiniu\base64_urlSafeEncode($url1);
$fops .= '/url/' . \Qiniu\base64_urlSafeEncode($url2);
$fops .= '|saveas/' . \Qiniu\base64_urlSafeEncode("$bucket:$zipKey");
list($id, $error) = $pfop->execute($bucket, $key, $fops);
$this->assertNull($error);
list($status, $error) = $pfop->status($id);
$this->assertNotNull($status);
$this->assertNull($error);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Qiniu\Tests;
use Qiniu\Storage\ResumeUploader;
use Qiniu\Storage\UploadManager;
use Qiniu\Config;
use Qiniu\Zone;
class ResumeUpTest extends \PHPUnit_Framework_TestCase
{
protected $bucketName;
protected $auth;
protected function setUp()
{
global $bucketName;
$this->bucketName = $bucketName;
global $testAuth;
$this->auth = $testAuth;
}
public function test4ML()
{
$key = 'resumePutFile4ML';
$upManager = new UploadManager();
$token = $this->auth->uploadToken($this->bucketName, $key);
$tempFile = qiniuTempFile(4 * 1024 * 1024 + 10);
list($ret, $error) = $upManager->putFile($token, $key, $tempFile);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
unlink($tempFile);
}
public function test4ML2()
{
$key = 'resumePutFile4ML';
$zone = new Zone(array('up.qiniup.com'));
$cfg = new Config($zone);
$upManager = new UploadManager($cfg);
$token = $this->auth->uploadToken($this->bucketName, $key);
$tempFile = qiniuTempFile(4 * 1024 * 1024 + 10);
list($ret, $error) = $upManager->putFile($token, $key, $tempFile);
$this->assertNull($error);
$this->assertNotNull($ret['hash']);
unlink($tempFile);
}
// public function test8M()
// {
// $key = 'resumePutFile8M';
// $upManager = new UploadManager();
// $token = $this->auth->uploadToken($this->bucketName, $key);
// $tempFile = qiniuTempFile(8*1024*1024+10);
// list($ret, $error) = $upManager->putFile($token, $key, $tempFile);
// $this->assertNull($error);
// $this->assertNotNull($ret['hash']);
// unlink($tempFile);
// }
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Qiniu\Tests;
use Qiniu;
use Qiniu\Zone;
class ZoneTest extends \PHPUnit_Framework_TestCase
{
protected $zone;
protected $zoneHttps;
protected $ak;
protected $bucketName;
protected $bucketNameBC;
protected $bucketNameNA;
protected function setUp()
{
global $bucketName;
$this->bucketName = $bucketName;
global $bucketNameBC;
$this->bucketNameBC = $bucketNameBC;
global $bucketNameNA;
$this->bucketNameNA = $bucketNameNA;
global $accessKey;
$this->ak = $accessKey;
$this->zone = new Zone();
$this->zoneHttps = new Zone('https');
}
public function testUpHosts()
{
$zone = Zone::queryZone($this->ak, $this->bucketName);
$this->assertContains('upload.qiniup.com', $zone->cdnUpHosts);
$zone = Zone::queryZone($this->ak, $this->bucketNameBC);
$this->assertContains('upload-z1.qiniup.com', $zone->cdnUpHosts);
$zone = Zone::queryZone($this->ak, $this->bucketNameNA);
$this->assertContains('upload-na0.qiniup.com', $zone->cdnUpHosts);
}
public function testIoHosts()
{
$zone = Zone::queryZone($this->ak, $this->bucketName);
$this->assertEquals($zone->iovipHost, 'iovip.qbox.me');
$zone = Zone::queryZone($this->ak, $this->bucketNameBC);
$this->assertEquals($zone->iovipHost, 'iovip-z1.qbox.me');
$zone = Zone::queryZone($this->ak, $this->bucketNameNA);
$this->assertEquals($zone->iovipHost, 'iovip-na0.qbox.me');
}
}

View File

@@ -0,0 +1,43 @@
<?php
// @codingStandardsIgnoreFile
require_once __DIR__ . '/../autoload.php';
use Qiniu\Auth;
$accessKey = getenv('QINIU_ACCESS_KEY');
$secretKey = getenv('QINIU_SECRET_KEY');
$testAuth = new Auth($accessKey, $secretKey);
$bucketName = 'phpsdk';
$key = 'php-logo.png';
$key2 = 'niu.jpg';
$bucketNameBC = 'phpsdk-bc';
$bucketNameNA = 'phpsdk-na';
$dummyAccessKey = 'abcdefghklmnopq';
$dummySecretKey = '1234567890';
$dummyAuth = new Auth($dummyAccessKey, $dummySecretKey);
//cdn
$timestampAntiLeechEncryptKey = getenv('QINIU_TIMESTAMP_ENCRPTKEY');
$customDomain = "http://phpsdk.qiniuts.com";
$tid = getenv('TRAVIS_JOB_NUMBER');
if (!empty($tid)) {
$pid = getmypid();
$tid = strstr($tid, '.');
$tid .= '.' . $pid;
}
function qiniuTempFile($size)
{
$fileName = tempnam(sys_get_temp_dir(), 'qiniu_');
$file = fopen($fileName, 'wb');
if ($size > 0) {
fseek($file, $size - 1);
fwrite($file, ' ');
}
fclose($file);
return $fileName;
}