审查视图

simplewind/vendor/qiniu/php-sdk/tests/Qiniu/Tests/CdnManagerTest.php 1.3 KB
董瑞恩 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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);
    }
}