Skip to content

Commit 34fc0e5

Browse files
committed
unit test for persistentOps
1 parent 0eb541c commit 34fc0e5

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

qiniu/rs.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class Qiniu_RS_PutPolicy
4949
public $AsyncOps;
5050
public $EndUser;
5151
public $Expires;
52-
public $PersistentOps;
53-
public $PersistentNotifyUrl;
52+
public $PersistentOps;
53+
public $PersistentNotifyUrl;
5454

5555
public function __construct($scope)
5656
{
@@ -84,10 +84,10 @@ public function Token($mac) // => $token
8484
if (!empty($this->EndUser)) {
8585
$policy['endUser'] = $this->EndUser;
8686
}
87-
if (!empty($this->PersistentOps) && !empty($this->PersistentNotifyUrl)) {
88-
$policy['persistentOps'] = $this->PersistentOps;
89-
$policy['persistentNotifyUrl'] = $this->PersistentNotifyUrl;
90-
}
87+
if (!empty($this->PersistentOps) && !empty($this->PersistentNotifyUrl)) {
88+
$policy['persistentOps'] = $this->PersistentOps;
89+
$policy['persistentNotifyUrl'] = $this->PersistentNotifyUrl;
90+
}
9191

9292
$b = json_encode($policy);
9393
return Qiniu_SignWithData($mac, $b);

tests/PersistentTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
require_once("bootstrap.php");
4+
5+
class PersistentTest extends PHPUnit_Framework_TestCase
6+
{
7+
public $bucket;
8+
public $client;
9+
10+
public function setUp()
11+
{
12+
initKeys();
13+
$this->client = new Qiniu_MacHttpClient(null);
14+
$this->bucket = getenv("QINIU_BUCKET_NAME");
15+
}
16+
17+
public function testPutFileWithPersistentOps()
18+
{
19+
$key = 'testPutFileWithPersistentOps' . getTid();
20+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
21+
22+
$putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
23+
$putPolicy->PersistentOps = 'avthumb/mp3';
24+
$putPolicy->PersistentNotifyUrl = 'http://someurl/abc';
25+
$upToken = $putPolicy->Token(null);
26+
$putExtra = new Qiniu_PutExtra();
27+
$putExtra->CheckCrc = 1;
28+
list($ret, $err) = Qiniu_PutFile($upToken, $key, __file__, $putExtra);
29+
$this->assertNull($err);
30+
$this->assertArrayHasKey('hash', $ret);
31+
$this->assertArrayHasKey('persistentId', $ret);
32+
var_dump($ret);
33+
34+
list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
35+
$this->assertNull($err);
36+
var_dump($ret);
37+
38+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
39+
$this->assertNull($err);
40+
}
41+
42+
public function testPutWithPersistentOps()
43+
{
44+
$key = 'testPutWithPersistentOps' . getTid();
45+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
46+
47+
$putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
48+
$putPolicy->PersistentOps = 'avthumb/mp3';
49+
$putPolicy->PersistentNotifyUrl = 'http://someurl/abc';
50+
$upToken = $putPolicy->Token(null);
51+
list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null);
52+
$this->assertNull($err);
53+
$this->assertArrayHasKey('hash', $ret);
54+
$this->assertArrayHasKey('persistentId', $ret);
55+
var_dump($ret);
56+
57+
list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
58+
$this->assertNull($err);
59+
var_dump($ret);
60+
61+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
62+
$this->assertNull($err);
63+
}
64+
}
65+

0 commit comments

Comments
 (0)