GetLifecycleResultTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Http\ResponseCore;
  4. use OSS\Core\OssException;
  5. use OSS\Model\LifecycleConfig;
  6. use OSS\Result\GetLifecycleResult;
  7. class GetLifecycleResultTest extends \PHPUnit_Framework_TestCase
  8. {
  9. private $validXml = <<<BBBB
  10. <?xml version="1.0" encoding="utf-8"?>
  11. <LifecycleConfiguration>
  12. <Rule>
  13. <ID>delete obsoleted files</ID>
  14. <Prefix>obsoleted/</Prefix>
  15. <Status>Enabled</Status>
  16. <Expiration><Days>3</Days></Expiration>
  17. </Rule>
  18. <Rule>
  19. <ID>delete temporary files</ID>
  20. <Prefix>temporary/</Prefix>
  21. <Status>Enabled</Status>
  22. <Expiration><Date>2022-10-12T00:00:00.000Z</Date></Expiration>
  23. <Expiration2><Date>2022-10-12T00:00:00.000Z</Date></Expiration2>
  24. </Rule>
  25. </LifecycleConfiguration>
  26. BBBB;
  27. public function testParseValidXml()
  28. {
  29. $response = new ResponseCore(array(), $this->validXml, 200);
  30. $result = new GetLifecycleResult($response);
  31. $this->assertTrue($result->isOK());
  32. $this->assertNotNull($result->getData());
  33. $this->assertNotNull($result->getRawResponse());
  34. $lifecycleConfig = $result->getData();
  35. $this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($lifecycleConfig->serializeToXml()));
  36. }
  37. private function cleanXml($xml)
  38. {
  39. return str_replace("\n", "", str_replace("\r", "", $xml));
  40. }
  41. public function testInvalidResponse()
  42. {
  43. $response = new ResponseCore(array(), $this->validXml, 300);
  44. try {
  45. new GetLifecycleResult($response);
  46. $this->assertTrue(false);
  47. } catch (OssException $e) {
  48. }
  49. }
  50. }