Skip to content

Commit

Permalink
add image tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertYue19900425 committed Nov 1, 2016
1 parent de0e679 commit c6f126b
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions tests/OSS/Tests/OssClientImageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace OSS\Tests;

require_once __DIR__ . '/Common.php';

use OSS\OssClient;
use OSS\Model\LiveChannelConfig;
use OSS\Model\LiveChannelInfo;
use OSS\Model\LiveChannelListInfo;
use OSS\Core\OssException;



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, 10));
$this->client->createBucket($this->bucketName);
Common::waitMetaSync();
sleep(30);
$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,
'x-oss-process' => "image/resize,m_fixed,h_100,w_100", );
$this->check($options, 100, 100, 3587, 'jpg');
}

public function testImageCrop()
{
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
'x-oss-process' => "image/crop,w_100,h_100,x_100,y_100,r_1", );
$this->check($options, 100, 100, 2281, 'jpg');
}

public function testImageRotate()
{
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
'x-oss-process' => "image/rotate,90", );
$this->check($options, 267, 400, 21509, 'jpg');
}

public function testImageSharpen()
{
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
'x-oss-process' => "image/sharpen,100", );
$this->check($options, 400, 267, 24183, 'jpg');
}

public function testImageWatermark()
{
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
'x-oss-process' => "image/watermark,text_SGVsbG8g5Zu-54mH5pyN5YqhIQ", );
$this->check($options, 400, 267, 26953, 'jpg');
}

public function testImageFormat()
{
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
'x-oss-process' => "image/format,png", );
$this->check($options, 400, 267, 160733, 'png');
}

public function testImageTofile()
{
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $this->download_file,
'x-oss-process' => "image/resize,m_fixed,w_100,h_100", );
$this->check($options, 100, 100, 3587, '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
$this->assertEquals($size, ceil(filesize($this->download_file)));
}
}

0 comments on commit c6f126b

Please sign in to comment.