ListMultipartUploadResultTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Result\ListMultipartUploadResult;
  4. use OSS\Http\ResponseCore;
  5. /**
  6. * Class ListMultipartUploadResultTest
  7. * @package OSS\Tests
  8. */
  9. class ListMultipartUploadResultTest extends \PHPUnit_Framework_TestCase
  10. {
  11. private $validXml = <<<BBBB
  12. <?xml version="1.0" encoding="UTF-8"?>
  13. <ListMultipartUploadsResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
  14. <Bucket>oss-example</Bucket>
  15. <KeyMarker>xx</KeyMarker>
  16. <UploadIdMarker>3</UploadIdMarker>
  17. <NextKeyMarker>oss.avi</NextKeyMarker>
  18. <NextUploadIdMarker>0004B99B8E707874FC2D692FA5D77D3F</NextUploadIdMarker>
  19. <Delimiter>x</Delimiter>
  20. <Prefix>xx</Prefix>
  21. <MaxUploads>1000</MaxUploads>
  22. <IsTruncated>false</IsTruncated>
  23. <Upload>
  24. <Key>multipart.data</Key>
  25. <UploadId>0004B999EF518A1FE585B0C9360DC4C8</UploadId>
  26. <Initiated>2012-02-23T04:18:23.000Z</Initiated>
  27. </Upload>
  28. <Upload>
  29. <Key>multipart.data</Key>
  30. <UploadId>0004B999EF5A239BB9138C6227D69F95</UploadId>
  31. <Initiated>2012-02-23T04:18:23.000Z</Initiated>
  32. </Upload>
  33. <Upload>
  34. <Key>oss.avi</Key>
  35. <UploadId>0004B99B8E707874FC2D692FA5D77D3F</UploadId>
  36. <Initiated>2012-02-23T06:14:27.000Z</Initiated>
  37. </Upload>
  38. </ListMultipartUploadsResult>
  39. BBBB;
  40. private $validXmlWithEncodedKey = <<<BBBB
  41. <?xml version="1.0" encoding="UTF-8"?>
  42. <ListMultipartUploadsResult xmlns="http://doc.oss-cn-hangzhou.aliyuncs.com">
  43. <Bucket>oss-example</Bucket>
  44. <EncodingType>url</EncodingType>
  45. <KeyMarker>php%2Bkey-marker</KeyMarker>
  46. <UploadIdMarker>3</UploadIdMarker>
  47. <NextKeyMarker>php%2Bnext-key-marker</NextKeyMarker>
  48. <NextUploadIdMarker>0004B99B8E707874FC2D692FA5D77D3F</NextUploadIdMarker>
  49. <Delimiter>%2F</Delimiter>
  50. <Prefix>php%2Bprefix</Prefix>
  51. <MaxUploads>1000</MaxUploads>
  52. <IsTruncated>true</IsTruncated>
  53. <Upload>
  54. <Key>php%2Bkey-1</Key>
  55. <UploadId>0004B999EF518A1FE585B0C9360DC4C8</UploadId>
  56. <Initiated>2012-02-23T04:18:23.000Z</Initiated>
  57. </Upload>
  58. <Upload>
  59. <Key>php%2Bkey-2</Key>
  60. <UploadId>0004B999EF5A239BB9138C6227D69F95</UploadId>
  61. <Initiated>2012-02-23T04:18:23.000Z</Initiated>
  62. </Upload>
  63. <Upload>
  64. <Key>php%2Bkey-3</Key>
  65. <UploadId>0004B99B8E707874FC2D692FA5D77D3F</UploadId>
  66. <Initiated>2012-02-23T06:14:27.000Z</Initiated>
  67. </Upload>
  68. </ListMultipartUploadsResult>
  69. BBBB;
  70. public function testParseValidXml()
  71. {
  72. $response = new ResponseCore(array(), $this->validXml, 200);
  73. $result = new ListMultipartUploadResult($response);
  74. $listMultipartUploadInfo = $result->getData();
  75. $this->assertEquals("oss-example", $listMultipartUploadInfo->getBucket());
  76. $this->assertEquals("xx", $listMultipartUploadInfo->getKeyMarker());
  77. $this->assertEquals(3, $listMultipartUploadInfo->getUploadIdMarker());
  78. $this->assertEquals("oss.avi", $listMultipartUploadInfo->getNextKeyMarker());
  79. $this->assertEquals("0004B99B8E707874FC2D692FA5D77D3F", $listMultipartUploadInfo->getNextUploadIdMarker());
  80. $this->assertEquals("x", $listMultipartUploadInfo->getDelimiter());
  81. $this->assertEquals("xx", $listMultipartUploadInfo->getPrefix());
  82. $this->assertEquals(1000, $listMultipartUploadInfo->getMaxUploads());
  83. $this->assertEquals("false", $listMultipartUploadInfo->getIsTruncated());
  84. $uploads = $listMultipartUploadInfo->getUploads();
  85. $this->assertEquals("multipart.data", $uploads[0]->getKey());
  86. $this->assertEquals("0004B999EF518A1FE585B0C9360DC4C8", $uploads[0]->getUploadId());
  87. $this->assertEquals("2012-02-23T04:18:23.000Z", $uploads[0]->getInitiated());
  88. }
  89. public function testParseValidXmlWithEncodedKey()
  90. {
  91. $response = new ResponseCore(array(), $this->validXmlWithEncodedKey, 200);
  92. $result = new ListMultipartUploadResult($response);
  93. $listMultipartUploadInfo = $result->getData();
  94. $this->assertEquals("oss-example", $listMultipartUploadInfo->getBucket());
  95. $this->assertEquals("php+key-marker", $listMultipartUploadInfo->getKeyMarker());
  96. $this->assertEquals("php+next-key-marker", $listMultipartUploadInfo->getNextKeyMarker());
  97. $this->assertEquals(3, $listMultipartUploadInfo->getUploadIdMarker());
  98. $this->assertEquals("0004B99B8E707874FC2D692FA5D77D3F", $listMultipartUploadInfo->getNextUploadIdMarker());
  99. $this->assertEquals("/", $listMultipartUploadInfo->getDelimiter());
  100. $this->assertEquals("php+prefix", $listMultipartUploadInfo->getPrefix());
  101. $this->assertEquals(1000, $listMultipartUploadInfo->getMaxUploads());
  102. $this->assertEquals("true", $listMultipartUploadInfo->getIsTruncated());
  103. $uploads = $listMultipartUploadInfo->getUploads();
  104. $this->assertEquals("php+key-1", $uploads[0]->getKey());
  105. $this->assertEquals("0004B999EF518A1FE585B0C9360DC4C8", $uploads[0]->getUploadId());
  106. $this->assertEquals("2012-02-23T04:18:23.000Z", $uploads[0]->getInitiated());
  107. }
  108. }