GetLoggingResultTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace OSS\Tests;
  3. use OSS\Result\GetLoggingResult;
  4. use OSS\Http\ResponseCore;
  5. use OSS\Core\OssException;
  6. class GetLoggingResultTest extends \PHPUnit_Framework_TestCase
  7. {
  8. private $validXml = <<<BBBB
  9. <?xml version="1.0" encoding="utf-8"?>
  10. <BucketLoggingStatus>
  11. <LoggingEnabled>
  12. <TargetBucket>TargetBucket</TargetBucket>
  13. <TargetPrefix>TargetPrefix</TargetPrefix>
  14. </LoggingEnabled>
  15. </BucketLoggingStatus>
  16. BBBB;
  17. public function testParseValidXml()
  18. {
  19. $response = new ResponseCore(array(), $this->validXml, 200);
  20. $result = new GetLoggingResult($response);
  21. $this->assertTrue($result->isOK());
  22. $this->assertNotNull($result->getData());
  23. $this->assertNotNull($result->getRawResponse());
  24. $loggingConfig = $result->getData();
  25. $this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($loggingConfig->serializeToXml()));
  26. $this->assertEquals("TargetBucket", $loggingConfig->getTargetBucket());
  27. $this->assertEquals("TargetPrefix", $loggingConfig->getTargetPrefix());
  28. }
  29. private function cleanXml($xml)
  30. {
  31. return str_replace("\n", "", str_replace("\r", "", $xml));
  32. }
  33. public function testInvalidResponse()
  34. {
  35. $response = new ResponseCore(array(), $this->validXml, 300);
  36. try {
  37. new GetLoggingResult($response);
  38. $this->assertTrue(false);
  39. } catch (OssException $e) {
  40. }
  41. }
  42. }