StorageCapacityTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Http\ResponseCore;
  4. use OSS\Model\StorageCapacityConfig;
  5. use OSS\Result\GetStorageCapacityResult;
  6. use OSS\Core\OssException;
  7. class StorageCapacityTest extends \PHPUnit_Framework_TestCase
  8. {
  9. private $inValidXml = <<<BBBB
  10. <?xml version="1.0" encoding="UTF-8"?>
  11. <BucketUserQos>
  12. <OssStorageCapacity>1</OssStorageCapacity>
  13. </BucketUserQos>
  14. BBBB;
  15. private $validXml = <<<BBBB
  16. <?xml version="1.0" encoding="UTF-8"?>
  17. <BucketUserQos>
  18. <StorageCapacity>1</StorageCapacity>
  19. </BucketUserQos>
  20. BBBB;
  21. public function testParseInValidXml()
  22. {
  23. $response = new ResponseCore(array(), $this->inValidXml, 300);
  24. try {
  25. new GetStorageCapacityResult($response);
  26. $this->assertTrue(false);
  27. } catch (OssException $e) {}
  28. }
  29. public function testParseEmptyXml()
  30. {
  31. $response = new ResponseCore(array(), "", 300);
  32. try {
  33. new GetStorageCapacityResult($response);
  34. $this->assertTrue(false);
  35. } catch (OssException $e) {}
  36. }
  37. public function testParseValidXml()
  38. {
  39. $response = new ResponseCore(array(), $this->validXml, 200);
  40. $result = new GetStorageCapacityResult($response);
  41. $this->assertEquals($result->getData(), 1);
  42. }
  43. public function testSerializeToXml()
  44. {
  45. $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<BucketUserQos><StorageCapacity>1</StorageCapacity></BucketUserQos>\n";
  46. $storageCapacityConfig = new StorageCapacityConfig(1);
  47. $content = $storageCapacityConfig->serializeToXml();
  48. $this->assertEquals($content, $xml);
  49. }
  50. }