|
| 1 | +<?php |
| 2 | + |
| 3 | +require("bootstrap.php"); |
| 4 | + |
| 5 | +class RsApiTest extends PHPUnit_Framework_TestCase |
| 6 | +{ |
| 7 | + public $client; |
| 8 | + public $bucket = BUCKET_NAME; |
| 9 | + public $notExistKey = "not_exist"; |
| 10 | + public $key1 = KEY_NAME; |
| 11 | + public $key2 = "file_name_2"; |
| 12 | + public $key3 = "file_name_3"; |
| 13 | + public $key4 = "file_name_4"; |
| 14 | + public function setUp() |
| 15 | + { |
| 16 | + $this->client = new Qiniu_Client(null); |
| 17 | + } |
| 18 | + |
| 19 | + public function testStat() |
| 20 | + { |
| 21 | + list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $this->key1); |
| 22 | + $this->assertArrayHasKey('hash', $ret); |
| 23 | + $this->assertNull($err); |
| 24 | + list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $this->notExistKey); |
| 25 | + $this->assertNull($ret); |
| 26 | + $this->assertFalse($err === null); |
| 27 | + } |
| 28 | + |
| 29 | + public function testDeleteMoveCopy() |
| 30 | + { |
| 31 | + Qiniu_RS_Delete($this->client, $this->bucket, $this->key2); |
| 32 | + Qiniu_RS_Delete($this->client, $this->bucket, $this->key3); |
| 33 | + |
| 34 | + $err = Qiniu_RS_Copy($this->client, $this->bucket, $this->key1, $this->bucket, $this->key2); |
| 35 | + $this->assertNull($err); |
| 36 | + $err = Qiniu_RS_Move($this->client, $this->bucket, $this->key2, $this->bucket, $this->key3); |
| 37 | + $this->assertNull($err); |
| 38 | + $err = Qiniu_RS_Delete($this->client, $this->bucket, $this->key3); |
| 39 | + $this->assertNull($err); |
| 40 | + $err = Qiniu_RS_Delete($this->client, $this->bucket, $this->key2); |
| 41 | + $this->assertNotNull($err, "delete key2 false"); |
| 42 | + } |
| 43 | + |
| 44 | + public function testBatchStat() |
| 45 | + { |
| 46 | + $entries = array(new Qiniu_RS_EntryPath($this->bucket, $this->key1), new Qiniu_RS_EntryPath($this->bucket, $this->key2)); |
| 47 | + list($ret, $err) = Qiniu_RS_BatchStat($this->client, $entries); |
| 48 | + $this->assertNotNull($err); |
| 49 | + $this->assertEquals($ret[0]['code'], 200); |
| 50 | + $this->assertEquals($ret[1]['code'], 612); |
| 51 | + } |
| 52 | + |
| 53 | + public function testBatchDeleteMoveCopy() |
| 54 | + { |
| 55 | + $e1 = new Qiniu_RS_EntryPath($this->bucket, $this->key1); |
| 56 | + $e2 = new Qiniu_RS_EntryPath($this->bucket, $this->key2); |
| 57 | + $e3 = new Qiniu_RS_EntryPath($this->bucket, $this->key3); |
| 58 | + $e4 = new Qiniu_RS_EntryPath($this->bucket, $this->key4); |
| 59 | + Qiniu_RS_BatchDelete($this->client, array($e2, $e3,$e4)); |
| 60 | + |
| 61 | + $entryPairs = array(new Qiniu_RS_EntryPathPair($e1, $e2), new Qiniu_RS_EntryPathPair($e1, $e3)); |
| 62 | + list($ret, $err) = Qiniu_RS_BatchCopy($this->client, $entryPairs); |
| 63 | + $this->assertNull($err); |
| 64 | + $this->assertEquals($ret[0]['code'], 200); |
| 65 | + $this->assertEquals($ret[0]['code'], 200); |
| 66 | + |
| 67 | + list($ret, $err) = Qiniu_RS_BatchMove($this->client, array(new Qiniu_RS_EntryPathPair($e2, $e4))); |
| 68 | + $this->assertNull($err); |
| 69 | + $this->assertEquals($ret[0]['code'], 200); |
| 70 | + |
| 71 | + list($ret, $err) = Qiniu_RS_BatchDelete($this->client, array($e3, $e4)); |
| 72 | + $this->assertNull($err); |
| 73 | + $this->assertEquals($ret[0]['code'], 200); |
| 74 | + $this->assertEquals($ret[0]['code'], 200); |
| 75 | + |
| 76 | + Qiniu_RS_BatchDelete($this->client, array($e2, $e3, $e4)); |
| 77 | + } |
| 78 | + |
| 79 | +} |
0 commit comments